//==================================================================
//  Copyright (C) 2006-2007  Davide Pasca
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//==================================================================
///
///
///
///
///
//==================================================================

#ifndef M5D_MESH_GEOMETRY_H
#define M5D_MESH_GEOMETRY_H

#include "pvector.h"
#include "m5d_types.h"
#include "m5d_verts.h"
#include "m5d_displist.h"

//==================================================================
namespace M5D {

//==================================================================
/// Vertices with multiple, separate properties.
//==================================================================
class MeshGeometry
{
public:
	autodel<DispList>	_displist_idxp;
	PSYS::sync_item				_displist_idxp_verts_syn;
	PSYS::sync_item				_displist_idxp_trigs_syn;

	autodel<DispList>	_displist_vtxp;
	PSYS::sync_item				_displist_vtxp_verts_syn;
	PSYS::sync_item				_displist_vtxp_trigs_syn;

	PMath::Vector3			_box_min, _box_max;
private:
	MultiVerts				_verts;
	Triangles				_trigs;

public:
	MeshGeometry()
	{
		_box_min.SetMaxValue();
		_box_max.SetMinValue();
	}

	~MeshGeometry()
	{
		SAFE_DELETE( _displist_idxp );
		SAFE_DELETE( _displist_vtxp );
	}

	MultiVerts			&GetVerts()			{	return _verts;	}
	const MultiVerts	&GetVerts()	 const	{	return _verts;	}
	
	Triangles		&GetTrigs()			{	return _trigs;	}
	const Triangles	&GetTrigs()	const	{	return _trigs;	}

	Triangle		&GetTriangle( u_int tidx )			{	return _trigs._list[tidx];	}
	const Triangle	&GetTriangle( u_int tidx )	const	{	return _trigs._list[tidx];	}

	//==================================================================
	DispList	*OpenDispListIndex( Scene *scenep, PackVert::Type packvert_type=PackVert::TYPE_ANY, u_int max_verts=0, u_int max_prim_indices=0 );
	DispList	*OpenDispListVertex( Scene *scenep, PackVert::Type packvert_type=PackVert::TYPE_ANY, u_int max_verts=0 );
	void		CloseDispListIndex();
	void		CloseDispListVertex();

	void		UpdateIdxDispList( Scene *scenep );
	void		UpdateVtxDispList( Scene *scenep, /*const*/ MeshGeometry *src_geomp=NULL, const bool *foced_vtypes=NULL );
};

//==================================================================
};

#endif